const addZero = (num) => {
  if(num >= 10) return num
  return '0' + num
}

export const formatDate = (date) => {
  if(!date) return

  const time = new Date(date)
  const y = time.getFullYear()
  const m = time.getMonth() + 1
  const d = time.getDate()
  const h = time.getHours()
  const min = time.getMinutes()
  const s = time.getSeconds()

  return `${y}-${addZero(m)}-${addZero(d)} ${addZero(h)}:${addZero(min)}:${addZero(s)}`
}

export const formatDate1 = (date) => {
  return new Date(date).toISOString().split('T')[0].replace(/-/g, '')
}

export function formatDateTimeWithMs(date) {
  const time = new Date(date)
  return [
    time.getFullYear(),
    (time.getMonth() + 1).toString().padStart(2, '0'),
    time.getDate().toString().padStart(2, '0')
  ].join('-') + ' ' + [
    time.getHours().toString().padStart(2, '0'),
    time.getMinutes().toString().padStart(2, '0'),
    time.getSeconds().toString().padStart(2, '0')
  ].join(':') + '.' + time.getMilliseconds().toString().padStart(3, '0');
}